Skip to content

Arm backend: Ensure data layout ops dtype validity#18540

Merged
AdrianLundell merged 5 commits intopytorch:mainfrom
AdrianLundell:change-1227017
Apr 20, 2026
Merged

Arm backend: Ensure data layout ops dtype validity#18540
AdrianLundell merged 5 commits intopytorch:mainfrom
AdrianLundell:change-1227017

Conversation

@AdrianLundell
Copy link
Copy Markdown
Collaborator

@AdrianLundell AdrianLundell commented Mar 27, 2026

Previously dtypes were not checked per tosa spec, leading to data layout ops (TRANSPOSE, RESHAPE...) sometimes being inserted as INT inf PRO-FP, which is invalid.

This patch adds checks and a new pass inserting dtype casts before/after all data layout ops to ensure validity.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell

Previously dtypes were not checked per tosa spec, leading to
data layout ops (TRANSPOSE, RESHAPE...) sometimes being
inserted as INT inf PRO-FP, which is invalid.

This patch adds checks and a new pass inserting dtype casts
before/after all data layout ops to ensure validity.

Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: I8e4d88a79e317727d5d0047f8c7aef1f87699bed
@AdrianLundell AdrianLundell added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk release notes: none Do not include this in the release notes labels Mar 27, 2026
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Mar 27, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18540

Note: Links to docs will display an error until the docs builds have been completed.

❌ 6 New Failures, 2 Cancelled Jobs, 3 Unrelated Failures

As of commit 736f22e with merge base 490ec5c (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 27, 2026
AdrianLundell and others added 3 commits April 7, 2026 10:12
Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: Iff630a5bd12d05119f14be37f819bdb28586a6d2
@zingo
Copy link
Copy Markdown
Collaborator

zingo commented Apr 15, 2026

Hi @digant this adds files

Copilot AI review requested due to automatic review settings April 20, 2026 10:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens Arm-backend TOSA dtype validation for data-layout-related ops and introduces a new lowering pass that inserts dtype casts around those ops to keep graphs valid under the active TOSA profile (notably FP-only / PRO-FP).

Changes:

  • Add InsertDataLayoutCastsPass to cast inputs/outputs around layout ops when the current TOSA profile doesn’t allow the op’s dtype.
  • Update several Arm operator lowerings (view/transpose/slice/pad/repeat/permute/cat) to validate allowed dtypes based on the active TOSA spec (integer/float support + extensions).
  • Add unit tests for the new pass (current coverage focuses on view_copy and cat).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
backends/arm/test/passes/test_insert_data_layout_casts_pass.py Adds tests asserting cast insertion behavior for view_copy and cat under FP profile.
backends/arm/operators/op_view.py Makes allowed dtypes depend on the active TOSA spec instead of a fixed list.
backends/arm/operators/op_tosa_transpose.py Same: spec-driven dtype validation for transpose lowering.
backends/arm/operators/op_tosa_slice.py Adds missing dtype/input-count validation for SLICE lowering (spec-driven).
backends/arm/operators/op_tosa_pad.py Adds missing dtype/input-count validation for PAD lowering (spec-driven).
backends/arm/operators/op_repeat.py Switches to spec-driven dtype validation for repeat/tile lowering.
backends/arm/operators/op_permute.py Switches to spec-driven dtype validation for permute/transpose lowering.
backends/arm/operators/op_cat.py Refines supported dtype logic to respect integer/float profile + int16/bf16 extensions.
backends/arm/_passes/insert_data_layout_casts_pass.py New pass that inserts _to_dim_order_copy casts around targeted layout ops based on TOSA profile support.
backends/arm/_passes/arm_pass_manager.py Wires InsertDataLayoutCastsPass into the default TOSA pipeline.
backends/arm/_passes/init.py Exports InsertDataLayoutCastsPass.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +65 to +67
def test_insert_data_layout_casts_no_target_view_fp_profile_skips_supported_dtype() -> (
None
):
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation here is split across multiple lines with parentheses, which is non-idiomatic and makes the signature harder to scan. Consider formatting it as a standard one-line -> None (or reflowing with a formatter) to match the style used by the other tests in this file.

Suggested change
def test_insert_data_layout_casts_no_target_view_fp_profile_skips_supported_dtype() -> (
None
):
def test_insert_data_layout_casts_no_target_view_fp_profile_skips_supported_dtype() -> None:

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +45
exir_ops.backend.tosa.TRANSPOSE.default,
exir_ops.edge.aten.constant_pad_nd.default,
exir_ops.edge.aten.view_copy.default,
exir_ops.edge.aten.repeat.default,
exir_ops.edge.aten.permute_copy.default,
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InsertDataLayoutCastsPass is intended to cover PAD and SLICE (per docstring/PR description), but targeted_ops currently only includes the edge forms (aten.constant_pad_nd, aten.slice_copy) while the main Arm TOSA pipeline rewrites these to exir_ops.backend.tosa.PAD.default and exir_ops.backend.tosa.SLICE.default (via RewritePadPass/RewriteSlicePass) before this pass runs. As a result, casts will not be inserted around the PAD/SLICE nodes that actually reach serialization in the real pipeline. Include the backend TOSA PAD/SLICE targets in targeted_ops (and ideally add a unit test that runs RewritePadPass/RewriteSlicePass before this pass to prevent regressions).

Suggested change
exir_ops.backend.tosa.TRANSPOSE.default,
exir_ops.edge.aten.constant_pad_nd.default,
exir_ops.edge.aten.view_copy.default,
exir_ops.edge.aten.repeat.default,
exir_ops.edge.aten.permute_copy.default,
exir_ops.backend.tosa.TRANSPOSE.default,
exir_ops.backend.tosa.PAD.default,
exir_ops.edge.aten.constant_pad_nd.default,
exir_ops.edge.aten.view_copy.default,
exir_ops.edge.aten.repeat.default,
exir_ops.edge.aten.permute_copy.default,
exir_ops.backend.tosa.SLICE.default,

Copilot uses AI. Check for mistakes.
@AdrianLundell
Copy link
Copy Markdown
Collaborator Author

No buck2 changes should be needed with this change:

  • The new pass file is auto-included by glob(["*.py"]) in backends/arm/_passes/TARGETS.
  • The new test file is auto-included by native.glob(["passes/test_*.py"]) in backends/arm/test/targets.bzl.
  • Operator changes are in existing files already covered by glob(["op_.py", "ops_.py"]) in backends/arm/operators/TARGETS.

Copy link
Copy Markdown
Collaborator

@zingo zingo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to merge

@AdrianLundell
Copy link
Copy Markdown
Collaborator Author

Fails not related

@AdrianLundell AdrianLundell merged commit 063f9c9 into pytorch:main Apr 20, 2026
413 of 426 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants